<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Jumper documentation</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>Jumper</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>



<h2>Examples</h2>
<ul>
  <li><a href="../examples/annotatedpathing.lua.html">annotatedpathing.lua</a></li>
  <li><a href="../examples/customheuristics.lua.html">customheuristics.lua</a></li>
  <li><strong>makeclearance.lua</strong></li>
  <li><a href="../examples/simpleexample.lua.html">simpleexample.lua</a></li>
</ul>
<h2>Modules</h2>
<ul>
  <li><a href="../modules/core.bheap.html">core.bheap</a></li>
  <li><a href="../modules/core.heuristics.html">core.heuristics</a></li>
  <li><a href="../modules/core.node.html">core.node</a></li>
  <li><a href="../modules/core.path.html">core.path</a></li>
  <li><a href="../modules/grid.html">grid</a></li>
  <li><a href="../modules/pathfinder.html">pathfinder</a></li>
</ul>

</div>

<div id="content">

<h1>Example <code>makeclearance.lua</code></h1>

    <pre>
<span class="comment">-- Tests sample for clearance metrics calculation
</span><span class="comment">-- See Figure 10 at http://aigamedev.com/open/tutorial/clearance-based-pathfinding/
</span><span class="keyword">local</span> Grid = <span class="global">require</span> <span class="string">'jumper.grid'</span>
<span class="keyword">local</span> PF = <span class="global">require</span> <span class="string">'jumper.pathfinder'</span>
<span class="keyword">local</span> map = {
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">2</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">2</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>},
	{<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>}
}
<span class="keyword">local</span> grid = Grid(map)
<span class="keyword">local</span> walkable = <span class="keyword">function</span>(v) <span class="keyword">return</span> v~=<span class="number">2</span> <span class="keyword">end</span>
<span class="keyword">local</span> finder = PF(grid, <span class="string">'ASTAR'</span>,walkable)
finder:annotateGrid()

<span class="keyword">for</span> y = <span class="number">1</span>, #map <span class="keyword">do</span>
	<span class="keyword">local</span> s = <span class="string">''</span>
	<span class="keyword">for</span> x = <span class="number">1</span>, #map[y] <span class="keyword">do</span>
	  <span class="keyword">local</span> node = grid:getNodeAt(x,y)
		s = (s .. <span class="string">' '</span> .. node:getClearance(walkable))
	<span class="keyword">end</span>
	<span class="global">print</span>(s)
<span class="keyword">end</span>

<span class="comment">-- Expected output
</span><span class="comment">--  6 6 5 5 4 4 4 3 2 1
</span><span class="comment">--  6 5 5 4 4 3 3 3 2 1
</span><span class="comment">--  6 5 4 4 3 3 2 2 2 1
</span><span class="comment">--  6 5 4 3 3 2 2 1 1 1
</span><span class="comment">--  6 5 4 3 2 2 1 1 0 1
</span><span class="comment">--  5 5 4 3 2 1 1 0 1 1
</span><span class="comment">--  4 4 4 3 2 1 0 2 1 0
</span><span class="comment">--  3 3 3 3 3 3 3 2 1 0
</span><span class="comment">--  2 2 2 2 2 2 2 2 2 1
</span><span class="comment">--  1 1 1 1 1 1 1 1 1 1
</span></pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
